<template>
	<el-card shadow="always">
		<el-form :inline="true">
			<!-- 一级产品 begin -->
			<el-form-item label="一级分类">
				<el-select
					placeholder="请选择"
					v-model="categoryStore.c1Id"
					@change="handler1"
					:disabled="scene ? true : false"
				>
					<el-option
						:label="c1.name"
						:value="c1.id"
						v-for="(c1, index) in categoryStore.c1Arr"
						:key="c1.id"
					></el-option>
				</el-select>
			</el-form-item>
			<!-- 一级产品 end -->
			<!-- 一级产品 begin -->
			<el-form-item label="二级分类">
				<el-select
					@change="handler2"
					v-model="categoryStore.c2Id"
					:disabled="scene ? true : false"
				>
					<el-option
						:label="c2.name"
						:value="c2.id"
						v-for="(c2, index) in categoryStore.c2Arr"
						:key="c2.id"
					></el-option>
				</el-select>
			</el-form-item>
			<!-- 一级产品 end -->
			<!-- 一级产品 begin -->
			<el-form-item label="三级分类">
				<el-select
					v-model="categoryStore.c3Id"
					:disabled="scene ? true : false"
				>
					<el-option
						:label="c3.name"
						:value="c3.id"
						v-for="(c3, index) in categoryStore.c3Arr"
						:key="c3.id"
					></el-option>
				</el-select>
			</el-form-item>
			<!-- 一级产品 end -->
		</el-form>
	</el-card>
</template>

<script setup>
	import { ref, onMounted } from 'vue';
	//获取小仓库
	import useCategoryStore from '@/stores/category';
	let categoryStore = useCategoryStore();
	//组件挂载后执行一次获取一级分类
	onMounted(() => {
		//通过pinia获取一级分类数据
		categoryStore.getC1();
	});

	//点击一级分类  获取二级分类的栏目
	const handler1 = () => {
		//一级分类id变化，清空二级三级id
		categoryStore.c2Id = '';
		categoryStore.c3Id = '';
		categoryStore.c3Arr = [];
		categoryStore.getC2();
	};
	//点击二级分类  获取三级分类的栏目
	const handler2 = () => {
		//点击二级分类  清空三级分类id
		categoryStore.c3Id = '';
		categoryStore.getC3();
	};

	//接受父组件传来的scene 控制下拉是否禁用
	let props = defineProps(['scene']);
</script>

<style lang="scss" scoped></style>
